<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('资产管理列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="notice-form">
                <div class="select-list">
                    <ul>
                        <li>
                            资产名称：<input type="text" name="assetName"/>
                        </li>
                        <li>
                            资产编号：<input type="text" name="assetNo"/>
                        </li>
                        <li>
                            资产类型：<select name="assetType" th:with="type=${@dict.getType('oa_asset_type')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                        </li>
                        <li>
                            资产状态：<select name="status" th:with="type=${@dict.getType('oa_asset_status')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="oa:asset:add">
                <i class="fa fa-plus"></i> 入库
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="oa:asset:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="oa:asset:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('oa:asset:edit')}]];
    var removeFlag = [[${@permission.hasPermi('oa:asset:remove')}]];

    var assetTypes = [[${@dict.getType('oa_asset_type')}]];
    var numUnits = [[${@dict.getType('oa_asset_num_unit')}]];
    var assetStatus = [[${@dict.getType('oa_asset_status')}]];

    var prefix = ctx + "oa/asset";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            modalName: "资产",
            showColumns: true,
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'assetNo',
                    title: '编号'
                },
                {
                    field: 'assetName',
                    title: '名称'
                },
                {
                    field: 'assetType',
                    title: '类型',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(assetTypes, value);
                    }
                },
                {
                    field: 'status',
                    title: '状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(assetStatus, value);
                    }
                },
                {
                    field: 'num',
                    title: '数量'
                },
                {
                    field: 'numUnit',
                    title: '单位',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(numUnits, value);
                    }
                },
                {
                    field: 'price',
                    title: '单价',
                    sortable: true
                },
                {
                    field: 'abradeRate',
                    title: '折损率',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (row.num > 0 && row.status == 0) {
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="lend(\'' + row.id + '\')"><i class="fa fa-edit"></i>领(借)用</a> ');
                        }
                        if (row.assetType != 0 && row.status == 1) {
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="revert(\'' + row.id + '\')"><i class="fa fa-edit"></i>归还</a> ');
                        }
                        if (row.num > 0 && row.assetType == 0) {
                            actions.push('<a class="btn btn-danger btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="back(\'' + row.id + '\')"><i class="fa fa-remove"></i>退库</a> ');
                        }
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="recode(\'' + row.id + '\')"><i class="fa fa-edit"></i>记录</a> ');

                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });
    /* 资产领用 */
    function lend(id) {
        var url = prefix + '/operate/add/' + id;
        $.modal.open("资产领用", url);
    }
    function recode(id) {
        var url = prefix + '/operate/detail/' + id;
        $.modal.open("操作记录", url);
    }
    function revert(id) {
        var url = prefix + '/operate/revert/' + id;
        $.modal.open("资产归还", url);
    }
    function back(id) {
        var url = prefix + '/operate/back/' + id;
        $.modal.open("资产退回", url);
    }
</script>
</body>
</html>